home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / bbs / s342q07.lha / stroll.c < prev    next >
C/C++ Source or Header  |  1993-06-18  |  11KB  |  394 lines

  1. /************************************************************************/
  2. /*                Stroll.C                */
  3. /*                      handles Stroll for Citadel-86                   */
  4. /************************************************************************/
  5. #define NO_STROLL
  6. #ifndef NO_STROLL
  7. #include "ctdl.h"
  8. /************************************************************************/
  9. /*                              history                    */
  10. /*                                    */
  11. /* 89Aug15 HAW  Created.                        */
  12. /************************************************************************/
  13. /************************************************************************/
  14. /*                              Contents                                */
  15. /*                                                                      */
  16. /*    StrollIt()        Handles a stroll call.            */
  17. /************************************************************************/
  18. /*
  19. This may need to be moved to a header file in the future.
  20. */
  21. #define TERMINATE    199
  22. #define SendBanner    88
  23. #define SendRoomlist    193
  24. #define SendBlurb    89
  25. #define DoGotoRoom    101
  26. #define NewMsgsStroll    80
  27. #define ReadForward    81 
  28. #define ReadReverse    82 
  29. #define ReadOldRev    83 
  30. #define DirStroll    84
  31. #define ExtDirStroll    85
  32. #define StrollStatus    86
  33. extern CONFIG      cfg;            /* Lots an lots of variables    */
  34. extern aRoom       roomBuf;        /* Room buffer                        */
  35. extern logBuffer   logBuf;         /* Log buffer of a person       */
  36. extern AN_UNSIGNED RecBuf[];
  37. extern struct floor  *FloorTab;
  38. extern rTable      *roomTab;       /* RAM index of rooms        */
  39. extern char        inNet;
  40. extern char       loggedIn;
  41. extern int       thisRoom;
  42. extern char        onConsole;      /* Flag                         */
  43. extern char        remoteSysop;
  44. void StrollMainLoop(void);
  45. void BannerStroll(void);
  46. void NoticeStroll(void);
  47. void GotoRoomStroll(struct cmd_data *cmds);
  48. void LogOutStroll(void);
  49. int StrollRoomInfo(int i);
  50. void SendStrollDir(struct cmd_data *cmds);
  51. void StrollReply(struct cmd_data *cmds);
  52. void SendStatus(void);
  53. char StrollValidate(int mode);
  54. void SendStrollMsgs(int mode, int revOrder, struct cmd_data *cmds);
  55. void KnownRoomsStroll(void);
  56. FILE *strollfd = NULL;
  57. /************************************************************************/
  58. /*    StrollIt() Handles a stroll call.                */
  59. /************************************************************************/
  60. void StrollIt()
  61.   {
  62.   char *User, *Pwd;
  63.   extern void (*NetPrintTarget)();
  64.   NetPrintTarget = mTrPrintf;
  65.   inNet = STROLL_CALL;
  66.   strollfd = fopen("strltest\\report", "w");
  67.   fprintf(strollfd, "In StrollIt()!\n");
  68.   if (called_stabilize()) 
  69.     {
  70.     fprintf(strollfd, "Stroll call\n");
  71.     printf("Stroll Call stabilized!\n");
  72.     ITL_InitCall();             /* Initialize the ITL layer */
  73.     ITL_Receive(NULL, FALSE, TRUE, putFLChar, fclose);
  74.     if (gotCarrier()) 
  75.       {
  76.       User = Pwd = RecBuf;
  77.       while (*Pwd)
  78.       Pwd++;
  79.       Pwd++;
  80.       if (PWSlot(Pwd, TRUE) != ERROR)
  81.       if (strCmpU(User, logBuf.lbname) == SAMESTRING)
  82.       StrollMainLoop();
  83.       pause(100);
  84.       killConnection();
  85.       
  86.       }
  87.     ITL_DeInit();
  88.     
  89.     }
  90.   fclose(strollfd);
  91.   strollfd = NULL;
  92.   inNet = NON_NET;
  93.   
  94.   }
  95. /************************************************************************/
  96. /*    StrollMainLoop() stroll caller's main loop.            */
  97. /************************************************************************/
  98. static void StrollMainLoop()
  99.   {
  100.   struct cmd_data cmds;
  101.   label           tempNm;
  102.   fprintf(strollfd, "Logged in as %s.\n", logBuf.lbname);
  103.   loggedIn     = TRUE;
  104.   setUp(TRUE);
  105.   do 
  106.     {
  107.     getNextCommand(&cmds);
  108.     fprintf(strollfd, "Requesting command %d.\n", cmds.command);
  109.     switch (cmds.command) 
  110.       {
  111.       case TERMINATE:
  112.       LogOutStroll();
  113.       break;
  114.       case SendBanner:
  115.       BannerStroll();
  116.       break;
  117.       case SendBlurb:
  118.       NoticeStroll();
  119.       break;
  120.       case SendRoomlist:
  121.       KnownRoomsStroll();
  122.       break;
  123.       case DoGotoRoom:
  124.       GotoRoomStroll(&cmds);
  125.       break;
  126.       case NewMsgsStroll:
  127.       SendStrollMsgs(NEWoNLY, FALSE, &cmds);
  128.       break;
  129.       case ReadForward:
  130.       SendStrollMsgs(OLDaNDnEW, FALSE, &cmds);
  131.       break;
  132.       case ReadReverse:
  133.       SendStrollMsgs(OLDaNDnEW, TRUE, &cmds);
  134.       break;
  135.       case ReadOldRev:
  136.       SendStrollMsgs(OLDoNLY, TRUE, &cmds);
  137.       break;
  138.       case DirStroll:
  139.       case ExtDirStroll:
  140.       SendStrollDir(&cmds);
  141.       break;
  142.       case StrollStatus:
  143.       SendStatus();
  144.       break;
  145.       default:
  146.       sPrintf(tempNm, "'%d' unknown.", cmds.command);
  147.       reply(BAD, tempNm);
  148.       break;
  149.       
  150.       }
  151.     
  152.     }
  153.   while (gotCarrier() && cmds.command != TERMINATE);
  154.   loggedIn = FALSE;
  155.   
  156.   }
  157. /************************************************************************/
  158. /*    LogOutStroll() log out on stroll.                */
  159. /************************************************************************/
  160. void LogOutStroll()
  161.   {
  162.   loggedIn     = FALSE;
  163.   reply(GOOD, "");
  164.   if (ITL_Send(STARTUP)) 
  165.     {
  166.     if (!MultiBanner("lonotice"))
  167.     HelpIfPresent("lonotice.blb");
  168.     ITL_Send(FINISH);
  169.     
  170.     }
  171.   
  172.   }
  173. /************************************************************************/
  174. /*    NoticeStroll() send the notice.                    */
  175. /************************************************************************/
  176. void NoticeStroll()
  177.   {
  178.   reply(GOOD, "");
  179.   if (ITL_Send(STARTUP)) 
  180.     {
  181.     if (!MultiBanner("notice"))
  182.     HelpIfPresent("notice.blb");
  183.     ITL_Send(FINISH);
  184.     
  185.     }
  186.   
  187.   }
  188. /************************************************************************/
  189. /*    BannerStroll() send the notice.                    */
  190. /************************************************************************/
  191. void BannerStroll()
  192.   {
  193.   extern char *VERSION;
  194.   reply(GOOD, "");
  195.   if (ITL_Send(STARTUP)) 
  196.     {
  197.     if (!MultiBanner("banner"))
  198.     if (!HelpIfPresent("banner.blb"))
  199.     mPrintf("Welcome to %s\n", cfg.codeBuf + cfg.nodeTitle);
  200.     mPrintf(" Running: %s (V%s) \n  ", VARIANT_NAME, VERSION);
  201.     mPrintf(formDate());
  202.     ITL_Send(FINISH);
  203.     
  204.     }
  205.   
  206.   }
  207. /************************************************************************/
  208. /*    KnownRoomsStroll() send the known rooms list            */
  209. /************************************************************************/
  210. void KnownRoomsStroll()
  211.   {
  212.   reply(GOOD, "");
  213.   if (ITL_Send(STARTUP)) 
  214.     {
  215.     tableRunner(StrollRoomInfo, TRUE);
  216.     sendITLchar(ETX);
  217.     ITL_Send(FINISH);
  218.     
  219.     }
  220.   
  221.   }
  222. /************************************************************************/
  223. /*    StrollRoomInfo() sends room info via STROLL.            */
  224. /************************************************************************/
  225. int StrollRoomInfo(int i)
  226.   {
  227.   char one, two;
  228.   /*
  229.   * A = '>'
  230.   * B = ')'
  231.   * C = ']'
  232.   * D = ':'
  233.   *
  234.   * 1 = Room has new messages
  235.   * 0 = Room has no new messages
  236.   */
  237.   static char matrix[2][2] =
  238.     {
  239.       {
  240.       'A', 'B' 
  241.       
  242.       }
  243.     ,
  244.       {
  245.       'C', 'D' 
  246.       
  247.       }
  248.     
  249.     };
  250.   one = roomTab[i].rtflags.ISDIR;
  251.   two = (roomTab[i].rtflags.SHARED && cfg.BoolFlags.netParticipant);
  252.   mTrPrintf("%s", roomTab[i].rtname);
  253.   mTrPrintf("%s", FloorTab[roomTab[i].rtFlIndex].FlName);
  254.   mTrPrintf("%c%c", matrix[one][two], RoomHasNew(i) ? '1' : '0');
  255.   return FALSE;
  256.   
  257.   }
  258. /************************************************************************/
  259. /*    GotoRoomStroll() goto a room via stroll.            */
  260. /************************************************************************/
  261. void GotoRoomStroll(struct cmd_data *cmds)
  262.   {
  263.   int count, NewCount;
  264.   if (GotoNamedRoom(cmds->fields[0], 'G') == ERROR)
  265.   reply(BAD, "No such room");
  266.   else 
  267.     {
  268.     cmds->command = GOOD;
  269.     CountMsgs(&count, &NewCount);
  270.     sPrintf(cmds->fields[0], "%d", count);
  271.     sPrintf(cmds->fields[1], "%d", NewCount);
  272.     StrollReply(cmds);
  273.     
  274.     }
  275.   
  276.   }
  277. /************************************************************************/
  278. /*      StrollReply() Replies to caller                    */
  279. /************************************************************************/
  280. void StrollReply(struct cmd_data *cmds)
  281.   {
  282.   int count;
  283.   if (!ITL_Send(STARTUP)) 
  284.     {
  285.     no_good("Couldn't send reply to %s!", TRUE);
  286.     return;
  287.     
  288.     }
  289.   sendITLchar(cmds->command);
  290.   for (count = 0; count < 4; count++) 
  291.     {
  292.     if (cmds->fields[count][0]) 
  293.       {
  294.       mTrPrintf("%s", cmds->fields[count]);
  295.       
  296.       }
  297.     
  298.     }
  299.   sendITLchar(0);
  300.   ITL_Send(FINISH);
  301.   
  302.   }
  303. /************************************************************************/
  304. /*    SendStrollMsgs() send user's messages.                */
  305. /************************************************************************/
  306. void SendStrollMsgs(int mode, int revOrder, struct cmd_data *cmds)
  307.   {
  308.   extern OptValues Opt;
  309.   reply(GOOD, "");
  310.   if (ITL_SendMessages()) 
  311.     {
  312.     zero_struct(Opt);
  313.     if (strCmp(cmds->fields[0], " ") != SAMESTRING) 
  314.       {
  315.       if (ReadDate(cmds->fields[0], &Opt.Date) == ERROR)
  316.       Opt.Date = -1l;
  317.       
  318.       }
  319.     else Opt.Date = -1l;
  320.     if (strCmp(cmds->fields[1], " ") != SAMESTRING)
  321.     strCpy(Opt.User, cmds->fields[1]);
  322.     if (strCmp(cmds->fields[2], " ") != SAMESTRING)
  323.     strCpy(Opt.Phrase, cmds->fields[2]);
  324.     showMessages(mode, revOrder,
  325.     logBuf.lbvisit[logBuf.lbgen[thisRoom] & CALLMASK],
  326.     StrollValidate);
  327.     ITL_StopSendMessages();
  328.     
  329.     }
  330.   
  331.   }
  332. /************************************************************************/
  333. /*    StrollValidate() should we send this message?            */
  334. /************************************************************************/
  335. char StrollValidate(int mode)
  336.   {
  337.   if (OptionCheck(mode))
  338.   prNetStyle(0, sendITLchar, TRUE, "");
  339.   return TRUE;
  340.   
  341.   }
  342. /************************************************************************/
  343. /*    SendStrollDir() send a directory via stroll.            */
  344. /************************************************************************/
  345. void SendStrollDir(struct cmd_data *cmds)
  346.   {
  347.   char Spec[50];
  348.   fprintf(strollfd, "In StrollDir.\n");
  349.   if (roomBuf.rbflags.ISDIR == 1 &&
  350.   (roomBuf.rbflags.DOWNLOAD || SomeSysop())) 
  351.     {
  352.     fprintf(strollfd, "StrollDir is replying GOOD.\n");
  353.     reply(GOOD, "");
  354.     fprintf(strollfd, "field0 is -%s-\nfield1 is -%s-\nfield2 is -%s-\nfield3 is -%s-.\n", cmds->fields[0], cmds->fields[1], cmds->fields[2], cmds->fields[3]);
  355.     sPrintf(Spec, "%s %s", cmds->fields[0], cmds->fields[1]);
  356.     if (ITL_Send(STARTUP)) 
  357.       {
  358.       doDirectory((cmds->command == DirStroll), Spec, cmds->fields[2]);
  359.       sendITLchar(ETX);
  360.       ITL_Send(FINISH);
  361.       
  362.       }
  363.     
  364.     }
  365.   else 
  366.     {
  367.     fprintf(strollfd, "StrollDir is replying BAD.\n");
  368.     reply(BAD, "No directory");
  369.     
  370.     }
  371.   
  372.   }
  373. /************************************************************************/
  374. /*    SendStatus() send .RS via stroll.                */
  375. /************************************************************************/
  376. void SendStatus()
  377.   {
  378.   reply(GOOD, "");
  379.   if (ITL_Send(STARTUP)) 
  380.     {
  381.     systat();
  382.     sendITLchar(ETX);
  383.     ITL_Send(FINISH);
  384.     
  385.     }
  386.   
  387.   }
  388. #else
  389. void StrollIt()
  390.   {
  391.   
  392.   }
  393. #endif
  394.